package com.example.jdt_xiazai.model;

import android.util.Log;

import com.example.jdt_xiazai.base.BaseModel;
import com.example.jdt_xiazai.bean.FuLiBean;
import com.example.jdt_xiazai.net.HttpUtil;
import com.example.jdt_xiazai.net.ResultCallBack;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class MainModel extends BaseModel {
    public void getData(final ResultCallBack resultCallBack){
        HttpUtil.getHttpUtil().getApiService().getData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<FuLiBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(FuLiBean fuLiBean) {
                        resultCallBack.onScanner(fuLiBean.getData().getDatas());
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("TAG", "onError: "+e.getMessage() );
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
